with open("D:/1.txt","r",encoding="UTF-8") as f:
    for line in f:
        print("每一行前缀",line)

#语法操作，打开并且添加文件内容
#如果 D:/1.txt文件不存在，将会自当创建
with open("D:/1.txt","w") as f:
    f.write("666")#将内容写到缓冲区中

with open("D:/2.txt", "w", encoding="UTF-8") as f:
    f.write("我是新添加的内容")
# 这里文件会自动关闭，无需手动调用f.close()

f=open("D:/1.txt","a",encoding="UTF-8")
f.write("我是新添加的内容")
f.close()#可以不调用  因为 write会自动关闭文件

with open("D:/1.txt","a",encoding="UTF-8") as f:
    f.write("我是新添加的内容")